const cloud = require('wx-server-sdk')
cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV,
})
const db = cloud.database()
exports.main = async (event, context) => {
  const {item} = event
  const result = await cloud.openapi.urllink.generate({
    "path": item.type == 0?'/pages/show/show':'/pages/image/image',
    "query": item._id
  })
  // let obj = {
  //   errcode: 0,
  //   errmsg: "ok",
  //   url_link: "URL Link"
  // }
  let url_link = result.url_link
  let res = await db.collection('links').doc(item._id).update({
    data:{
      link:url_link
    }
  })
  return result
  // 生成成功后根据id更新link
}